package com.example.musicapi.controller;

import com.example.musicapi.entity.Record;
import com.example.musicapi.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/record")
public class RecordController {
    @Autowired
    private RecordService recordService;

    @PostMapping("/get")
    @ResponseBody
    public List<Record> getAll( String user) {
        return recordService.search( user);
    }

    @PostMapping("/add")
    public String add(  Record u) {
        u = recordService.add(u);
        if (u != null && u.getId() != null)
            return "success";
        else {
            return "fail";
        }

    }

    /**
     * 当前用户的推荐列表
     * @param user  用户信息
     * @return  返回集合
     */
    @GetMapping("/recommendList")
    @ResponseBody
    public List<String> recommendList( String user) {
        return recordService.recommendList(user);
    }

}

